home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 September / Australian PC User - September 2003 (CD1).iso / magstuff / web / files / dwmx61.exe / Disk1 / data1.cab / Configuration_En / ServerModels / ColdFusion / dwscriptsServerImpl.js < prev   
Encoding:
JavaScript  |  2002-11-25  |  24.4 KB  |  914 lines

  1. // Copyright 2002 Macromedia, Inc. All rights reserved.
  2.  
  3. // *************** GLOBALS VARS *****************
  4.  
  5. // ***************** LOCAL FUNCTIONS  ******************
  6.  
  7. //--------------------------------------------------------------------
  8. // FUNCTION:
  9. //   queueDefaultDocEdits
  10. //
  11. // DESCRIPTION:
  12. //   This function is called before the docEdits are applied to the
  13. //   page to allow any default doc edits to be added.
  14. //
  15. // ARGUMENTS:
  16. //   none
  17. //
  18. // RETURNS:
  19. //   nothing
  20. //--------------------------------------------------------------------
  21.  
  22. function queueDefaultDocEdits()
  23. {
  24.   var partList = null;
  25.   
  26.   partList = dw.getParticipants("PageDirective_processDir");
  27.   if (partList && partList.length)
  28.   {
  29.     dwscripts.queueParticipantInfo("PageDirective_processDir", partList[0].participantNode);
  30.   }
  31.   
  32.   partList = dw.getParticipants("PageDirective_content");
  33.   if (partList && partList.length)
  34.   {
  35.     dwscripts.queueParticipantInfo("PageDirective_content", partList[0].participantNode);
  36.   }
  37.  
  38.   partList = dw.getParticipants("PageDirective_setEncoding");
  39.   if (partList && partList.length)
  40.   {
  41.     for (var i=0; i < partList.length; i++)
  42.     {
  43.        dwscripts.queueParticipantInfo("PageDirective_setEncoding", partList[i].participantNode);
  44.     }
  45.   }
  46. }
  47.  
  48.  
  49. //--------------------------------------------------------------------
  50. // FUNCTION:
  51. //   encodeDynamicExpression
  52. //
  53. // DESCRIPTION:
  54. //   This function prepares a dynamic expression for insertion onto
  55. //   the page.  It is assumed that this expression will be used
  56. //   within a larger dynamic statement, therefore all server markup
  57. //   is stripped.
  58. //
  59. // ARGUMENTS:
  60. //   expression - string - the dyanmic expression to encode
  61. //
  62. // RETURNS:
  63. //   string
  64. //--------------------------------------------------------------------
  65.  
  66. function encodeDynamicExpression(expression)
  67. {
  68.   var retVal = "";
  69.   expression = expression.toString();
  70.  
  71.   if (hasServerMarkup(expression))
  72.   {
  73.     retVal = trimServerMarkup(expression, true);
  74.   }
  75.   else
  76.   {
  77.     var parameters = expression.match(/(true|false|[-]?\d+[\.]?\d*)/i);
  78.     if (parameters && parameters[0].length == expression.length) // matches, return exact
  79.     {
  80.       retVal = expression;
  81.     }
  82.     else
  83.     {
  84.       if (!dwscripts.isQuoted(expression))
  85.       {
  86.         retVal = "\"" + dwscripts.escQuotes(expression) + "\"";
  87.       }
  88.       else
  89.       {
  90.         retVal = expression;
  91.       }
  92.     }
  93.   }
  94.  
  95.   return retVal;
  96. }
  97.  
  98.  
  99. //--------------------------------------------------------------------
  100. // FUNCTION:
  101. //   decodeDynamicExpression
  102. //
  103. // DESCRIPTION:
  104. //   This function prepares a dynamic expression for display within
  105. //   a dialog box.  Quotes are removed,a nd server markup is re-added.
  106. //
  107. // ARGUMENTS:
  108. //   expression - string - the dynamic expression to prepare for display
  109. //
  110. // RETURNS:
  111. //   string
  112. //--------------------------------------------------------------------
  113.  
  114. function decodeDynamicExpression(expression)
  115. {
  116.   var retVal = "";
  117.  
  118.   expression = dwscripts.trim(expression.toString());
  119.   var unquoted = dwscripts.trimQuotes(expression);
  120.  
  121.   var parameters = unquoted.match(/(true|false|[-]?\d+[\.]?\d*)/i);
  122.   if (parameters && parameters[0].length == unquoted.length) // matches, return exact
  123.   {
  124.     retVal = expression;
  125.   }
  126.   else
  127.   {
  128.     if (dwscripts.isQuoted(expression))
  129.     {
  130.       retVal = dwscripts.unescQuotes(unquoted);
  131.     }
  132.     else if (!(   expression.charAt(0) == "#"
  133.                && expression.charAt(expression.length-1) == "#"
  134.               )
  135.             )
  136.     {
  137.       retVal = "#" + expression +"#";  // no need to add cfoutput tags
  138.     }
  139.     else
  140.     {
  141.       retVal = expression;
  142.     }
  143.   }
  144.  
  145.   return retVal;
  146. }
  147.  
  148.  
  149. //--------------------------------------------------------------------
  150. // FUNCTION:
  151. //   hasServerMarkup
  152. //
  153. // DESCRIPTION:
  154. //   This function returns true if the given expression contains
  155. //   server markup.
  156. //
  157. // ARGUMENTS:
  158. //   expression - string - the expression to test for server markup
  159. //
  160. // RETURNS:
  161. //   boolean
  162. //--------------------------------------------------------------------
  163.  
  164. function hasServerMarkup(expression)
  165. {
  166.   var retVal = false;
  167.  
  168.   expression = expression.toString();
  169.  
  170.   var exp1 = /<cfoutput[^>]*>/gi;
  171.   var exp2 = /<\/cfoutput>/gi;
  172.   if ((expression.search(exp1) != -1 && expression.search(exp2) != -1))
  173.   {
  174.     retVal = true;
  175.   }
  176.  
  177.   if (!retVal)
  178.   {
  179.     // search for the starting and closing pound signs
  180.     //  need to handle pound signs escaped with double pounds
  181.  
  182.     var beginindex = expression.indexOf("#");
  183.     while (beginindex != -1)
  184.     {
  185.       if (beginindex+1 >= expression.length || expression.charAt(beginindex+1) != "#")
  186.       {
  187.         break;
  188.       }
  189.       beginindex = expression.indexOf("#", beginindex+2);
  190.     }
  191.     if (beginindex != -1)
  192.     {
  193.       var endindex = expression.indexOf("#", beginindex+1);
  194.       while (endindex != -1)
  195.       {
  196.         if (endindex+1 >= expression.length || expression.charAt(endindex+1) != "#")
  197.         {
  198.           break;
  199.         }
  200.         endindex = expression.indexOf("#", endindex+2);
  201.       }
  202.  
  203.       if (beginindex != -1 && endindex != -1)
  204.       {
  205.         retVal = true;
  206.       }
  207.     }
  208.   }
  209.  
  210.   return retVal;
  211. }
  212.  
  213.  
  214. //--------------------------------------------------------------------
  215. // FUNCTION:
  216. //   trimServerMarkup
  217. //
  218. // DESCRIPTION:
  219. //   This function returns the given expression with any server markup
  220. //   removed.
  221. //
  222. // ARGUMENTS:
  223. //   expression - string - the expression to remove server markup from
  224. //   ignorePoundSigns - boolean - if true, the pound signs will not
  225. //     be removed from the expression
  226. //
  227. // RETURNS:
  228. //   string
  229. //--------------------------------------------------------------------
  230.  
  231. function trimServerMarkup(expression, ignorePoundSigns)
  232. {
  233.   var retVal = expression.toString();
  234.  
  235.   var exp1 = /<cfoutput[^>]*>/gi;
  236.   var exp2 = /<\/cfoutput[^>]*>/gi;
  237.  
  238.   retVal = retVal.replace(exp1,"");
  239.   retVal = retVal.replace(exp2,"");
  240.  
  241.   if (!ignorePoundSigns)
  242.   {
  243.     // search for the starting and closing pound signs
  244.     //  need to handle pound signs escaped with double pounds
  245.  
  246.     var beginindex = retVal.indexOf("#");
  247.     while (beginindex != -1)
  248.     {
  249.       if (beginindex+1 >= retVal.length || retVal.charAt(beginindex+1) != "#")
  250.       {
  251.         break;
  252.       }
  253.       beginindex = retVal.indexOf("#", beginindex+2);
  254.     }
  255.     if (beginindex != -1)
  256.     {
  257.       var endindex = retVal.indexOf("#", beginindex+1);
  258.       while (endindex != -1)
  259.       {
  260.         if (endindex+1 >= retVal.length || retVal.charAt(endindex+1) != "#")
  261.         {
  262.           break;
  263.         }
  264.         endindex = retVal.indexOf("#", endindex+2);
  265.       }
  266.       if (beginindex != -1 && endindex != -1)
  267.       {
  268.         retVal = retVal.substring(beginindex+1,endindex);
  269.       }
  270.     }
  271.   }
  272.  
  273.   retVal = dwscripts.trim(retVal);
  274.  
  275.   return retVal;
  276. }
  277.  
  278.  
  279. //--------------------------------------------------------------------
  280. // FUNCTION:
  281. //   preprocessDocEditInsertText
  282. //
  283. // DESCRIPTION:
  284. //   This function is called during dwscripts.applyDocEdits(), to
  285. //   allow the Server Models to pre-process the inserted text.
  286. //   It returns he processed string which should be inserted into
  287. //   the document.
  288. //
  289. //   For Cold Fusion, we need to strip any nested CFOUTPUT tags
  290. //
  291. // ARGUMENTS:
  292. //   insertText - string - the text that will be inserted
  293. //   editNode - DOM node - the location where this text will be inserted
  294. //   isUpdate - boolean - true if we are updating the node, rather
  295. //     than inserting for the first time.
  296. //
  297. // RETURNS:
  298. //   string - the new insert text
  299. //--------------------------------------------------------------------
  300.  
  301. function preprocessDocEditInsertText(insertText, editNode, isUpdate)
  302. {
  303.   var retVal = String(insertText);
  304.  
  305.   if (retVal)
  306.   {
  307.     var indexStartCFOutput = retVal.search(/<cfoutput/i);
  308.     if (indexStartCFOutput != -1) //if contains <cfoutput>
  309.     {
  310.       var callback = new Object();
  311.       callback.tagName = "";
  312.       callback.queryAttr = "";
  313.       callback.tagEnd = false;
  314.       callback.openTagBegin = new Function("tag,offset","if (!this.tagName) { this.tagName = tag.toUpperCase(); }");
  315.       callback.attribute = new Function("name,code","if (!this.tagEnd && !this.queryAttr && name.toUpperCase() == \"QUERY\") { this.queryAttr = code; }");
  316.       callback.openTagEnd = new Function("","this.tagEnd = true;");
  317.  
  318.       dw.scanSourceString(retVal, callback);
  319.       
  320.       // If this is a repeat region, strip the inner tags
  321.       if (callback.tagName == "CFOUTPUT" &&
  322.           callback.queryAttr != "")
  323.       {
  324.         // don't strip any cfoutputs if we are updating a repeat region
  325.         if (!isUpdate)
  326.         {
  327.           // The insertText may contain nested cfoutputs. We must remove the inner
  328.           //   cfoutputs. A scenario where this might occur is if we are wrapping
  329.           //   dynamic text with a repeat region. In this case, the insert becomes
  330.           //   a replace of the dynamic text cfoutput node with the repeat region
  331.           //   cfoutput enclosing the dynamic text cfoutput as the insert text.
  332.           var capsRetVal = retVal.toUpperCase();
  333.           var indexEndCFOutput = capsRetVal.lastIndexOf("</CFOUTPUT");
  334.           var innerSlice = retVal.substring(indexStartCFOutput + 1, indexEndCFOutput + 1);
  335.           var innerSliceSansCFOutputs = dwscripts.stripCFOutputTags(innerSlice);
  336.           retVal = retVal.substring(0, indexStartCFOutput + 1)
  337.                  + innerSliceSansCFOutputs
  338.                  + retVal.substring(indexEndCFOutput + 1);
  339.         }
  340.       }
  341.       else
  342.       {
  343.         var dom = dw.getDocumentDOM();
  344.         if (dom)
  345.         {
  346.           // If we have an edit node, turn it into offsets.
  347.           var charRange = null;
  348.           if (editNode)
  349.           {
  350.             var offsets = dom.nodeToOffsets(editNode);
  351.             charRange = {startoffset: offsets[0], endoffset: offsets[1]};
  352.           }
  353.  
  354.           if (dwscripts.canStripCfOutputTags(charRange))
  355.           {
  356.             retVal = dwscripts.stripCFOutputTags(retVal);
  357.           }
  358.         }
  359.       }
  360.     }
  361.   }
  362.  
  363.   return retVal;
  364. }
  365.  
  366.  
  367. //--------------------------------------------------------------------
  368. // FUNCTION:
  369. //   getDBColumnTypeAsString
  370. //
  371. // DESCRIPTION:
  372. //   Maps the enumerated number used by the database to represent a type to the
  373. //   corresponding sql type string.
  374. //
  375. // ARGUMENTS:
  376. //   typeNum - enumerated number. Number used by the database to represent
  377. //     the type.
  378. //
  379. // RETURNS:
  380. //   string - ColdFusion SQL type string. null if typeNum is not found.
  381. //--------------------------------------------------------------------
  382.  
  383. function getDBColumnTypeAsString(typeNum)
  384. {
  385. // todo: should store dbtype array somewhere like in dwscripts?
  386.   var retVal = null;
  387.   var a = new Array();
  388.  
  389.   a[0] = "Empty";
  390.   a[2] = "CF_SQL_SMALLINT";
  391.   a[3] = "CF_SQL_INTEGER";
  392.   a[4] = "CF_SQL_FLOAT";
  393.   a[5] = "CF_SQL_FLOAT";
  394.   a[6] = "CF_SQL_MONEY";
  395.   a[7] = "CF_SQL_DATE";
  396.   a[8] = "CF_SQL_CHAR"; //?
  397.   a[9] = "IDispatch";
  398.   a[10] = "Error";
  399.   a[11] = "CF_SQL_BIT"; //Boolean
  400.   a[12] = "Variant";
  401.   a[13] = "IUnknown";
  402.   a[14] = "CF_SQL_DECIMAL"; //Decimal
  403.   a[16] = "CF_SQL_TINYINT"; //TinyInt
  404.   a[17] = "CF_SQL_TINYINT"; //UnsignedTinyInt
  405.   a[18] = "CF_SQL_SMALLINT"; //UnsignedSmallInt
  406.   a[19] = "CF_SQL_INTEGER"; //UnsignedInt
  407.   a[20] = "CF_SQL_BIGINT"; //BigInt
  408.   a[21] = "CF_SQL_BIGINT"; //UnsignedBigInt
  409.   a[72] = "GUID";
  410.   a[128] = "Binary";
  411.   a[129] = "CF_SQL_CHAR"; //Char
  412.   a[130] = "CF_SQL_CHAR"; //WChar
  413.   a[131] = "CF_SQL_NUMERIC"; //Numeric
  414.   a[132] = "UserDefined";
  415.   a[133] = "CF_SQL_DATE"; //DBDate
  416.   a[134] = "CF_SQL_TIME"; //DBTime
  417.   a[135] = "CF_SQL_TIMESTAMP"; //DBTimeStamp
  418.   a[200] = "CF_SQL_VARCHAR"; //VarChar
  419.   a[201] = "CF_SQL_LONGVARCHAR"; //LongVarChar
  420.   a[202] = "CF_SQL_VARCHAR"; //VarWChar
  421.   a[203] = "CF_SQL_LONGVARCHAR"; //LongVarWChar
  422.   a[204] = "VarBinary";
  423.   a[205] = "LongVarBinary";
  424.   //Defined for CF support
  425.   a[400] = "CF_SQL_REAL";
  426.   a[401] = "CF_SQL_FLOAT";
  427.   a[402] = "CF_SQL_LONGVARCHAR";
  428.   a[403] = "CF_SQL_MONEY4";
  429.   a[900] = "REF CURSOR" // Special case for Oracle
  430.   a[901] = "CF_SQL_BIT";
  431.  
  432.   if (a[typeNum])
  433.   {
  434.     retVal = a[typeNum];
  435.   }
  436.  
  437.   return retVal;
  438. }
  439.  
  440.  
  441. //--------------------------------------------------------------------
  442. // FUNCTION:
  443. //   getColumnValueNode
  444. //
  445. // DESCRIPTION:
  446. //   This function returns a platform specific instance of the
  447. //   ColumnValueNode class.  This function is called by dwscripts,
  448. //   and serves as a factory method.
  449. //
  450. // ARGUMENTS:
  451. //   none
  452. //
  453. // RETURNS:
  454. //   CFColumnValueNode object
  455. //--------------------------------------------------------------------
  456.  
  457. function getColumnValueNode()
  458. {
  459.   var retVal = new CFColumnValueNode();
  460.   return retVal;
  461. }
  462.  
  463.  
  464.  
  465.  
  466.  
  467. //--------------------------------------------------------------------
  468. // CLASS:
  469. //   CFColumnValueNode
  470. //
  471. // DESCRIPTION:
  472. //   This class represents the mapping of a database column to a value.
  473. //
  474. // PUBLIC PROPERTIES:
  475. //   None
  476. //
  477. // PUBLIC FUNCTIONS:
  478. //   See the base class in:
  479. //     Configuration/Shared/Common/Scripts/ColumnValueNodeClass.js
  480. //
  481. //--------------------------------------------------------------------
  482.  
  483. //--------------------------------------------------------------------
  484. // FUNCTION:
  485. //   CFColumnValueNode
  486. //
  487. // DESCRIPTION:
  488. //   Consructor function for the ColdFusion specific ColumnValueNode class
  489. //
  490. // ARGUMENTS:
  491. //   none
  492. //
  493. // RETURNS:
  494. //   nothing
  495. //--------------------------------------------------------------------
  496.  
  497. function CFColumnValueNode()
  498. {
  499.   this.initialize();
  500. }
  501.  
  502. // Inherit from the ColumnValueNode class.
  503. CFColumnValueNode.prototype.__proto__ = ColumnValueNode.prototype;
  504.  
  505. CFColumnValueNode.prototype.encodeSQLVarRef = CFColumnValueNode_encodeSQLVarRef;
  506. CFColumnValueNode.prototype.decodeSQLVarRef = CFColumnValueNode_decodeSQLVarRef;
  507.  
  508. CFColumnValueNode.prototype.getRuntimeValue = CFColumnValueNode_getRuntimeValue;
  509. CFColumnValueNode.prototype.setRuntimeValue = CFColumnValueNode_setRuntimeValue;
  510.  
  511.  
  512. //--------------------------------------------------------------------
  513. // FUNCTION:
  514. //   CFColumnValueNode.encodeSQLVarRef
  515. //
  516. // DESCRIPTION:
  517. //   Given a variable name and a wrap character, returns a string
  518. //   suitable for insertion into a SQL statement
  519. //
  520. // ARGUMENTS:
  521. //   variable - string - the variable reference to encode
  522. //   wrapChar - string - the character to enclose the reference in
  523. //
  524. // RETURNS:
  525. //   string
  526. //--------------------------------------------------------------------
  527.  
  528. function CFColumnValueNode_encodeSQLVarRef(variable, wrapChar)
  529. {
  530.   var sqlVarRef = "#" + variable + "#";
  531.  
  532.   if (wrapChar)
  533.   {
  534.     // Must escape a wrapchar of '#'
  535.     if (wrapChar == "#")
  536.     {
  537.       wrapChar = "##";
  538.     }
  539.     sqlVarRef = wrapChar + sqlVarRef + wrapChar;
  540.   }
  541.  
  542.   return sqlVarRef;
  543. }
  544.  
  545.  
  546. //--------------------------------------------------------------------
  547. // FUNCTION:
  548. //   CFColumnValueNode.decodeSQLVarRef
  549. //
  550. // DESCRIPTION:
  551. //   Given a SQL variable reference, this function extracts the
  552. //   variable name and the wrap character.
  553. //
  554. // ARGUMENTS:
  555. //   sqlVarRef - string - the SQL variable reference to decode
  556. //
  557. // RETURNS:
  558. //   object with two properties: variable and wrapChar
  559. //--------------------------------------------------------------------
  560.  
  561. function CFColumnValueNode_decodeSQLVarRef(sqlVarRef)
  562. {
  563.   var retVal = new Object();
  564.   retVal.value = sqlVarRef;
  565.   retVal.variable = "";
  566.   retVal.wrapChar = "";
  567.  
  568.   if (sqlVarRef.charAt(0) == sqlVarRef.charAt(sqlVarRef.length-1))
  569.   {
  570.     if (sqlVarRef.indexOf("###") == -1)
  571.     {
  572.       if (sqlVarRef.charAt(0) != "#")
  573.       {
  574.         retVal.wrapChar = sqlVarRef.charAt(0);
  575.         retVal.variable = sqlVarRef.substring(1,sqlVarRef.length-1);
  576.         if (retVal.variable.charAt(0) == retVal.variable.charAt(retVal.variable.length-1) &&
  577.             retVal.variable.charAt(0) == "#")
  578.         {
  579.           retVal.variable = retVal.variable.substring(1,retVal.variable.length-1);
  580.         }
  581.         else
  582.         {
  583.           // this is not a variable
  584.           retVal.variable = "";
  585.           retVal.wrapChar = "";
  586.         }
  587.       }
  588.       else
  589.       {
  590.         retVal.variable = sqlVarRef.substring(1,sqlVarRef.length-1);
  591.       }
  592.     }
  593.     else
  594.     {
  595.       // this is an access date, handle differently
  596.       retVal.wrapChar = "#";
  597.       retVal.variable = sqlVarRef.substring(3,sqlVarRef.length-3);
  598.     }
  599.   }
  600.  
  601.   return retVal;
  602. }
  603.  
  604.  
  605. //--------------------------------------------------------------------
  606. // FUNCTION:
  607. //   CFColumnValueNode.getRuntimeValue
  608. //
  609. // DESCRIPTION:
  610. //   Returns the runtime value suitable for insertion into a SQL
  611. //   statement, for this column value mapping.
  612. //
  613. //   NOTE: This is an override of a base class method
  614. //
  615. // ARGUMENTS:
  616. //   none
  617. //
  618. // RETURNS:
  619. //   string
  620. //--------------------------------------------------------------------
  621.  
  622. function CFColumnValueNode_getRuntimeValue()
  623. {
  624.   this.runtimeValue = "";
  625.  
  626.   if (this.varName)
  627.   {
  628.     this.runtimeValue = this.encodeSQLVarRef(this.varName, this.wrapChar);
  629.  
  630.     if (!this.isPrimaryKey)
  631.     {
  632.       if (this.altValue && this.defaultValue)
  633.       {
  634.         // generate the value for this column
  635.         var paramObj = new Object();
  636.         paramObj.Variable = this.varName;
  637.         paramObj.AltValue = this.altValue;
  638.         paramObj.DefaultValue = this.defaultValue;
  639.  
  640.         this.runtimeValue = extPart.getInsertString("", "SQLVariable_altValue", paramObj);
  641.       }
  642.       else if (this.defaultValue)
  643.       {
  644.         // generate the value for this column
  645.         var paramObj = new Object();
  646.         paramObj.Variable = this.varName;
  647.         paramObj.RuntimeValue = this.runtimeValue;
  648.         paramObj.DefaultValue = this.defaultValue;
  649.  
  650.         this.runtimeValue = extPart.getInsertString("", "SQLVariable_defaultValue", paramObj);
  651.       }
  652.     }
  653.   }
  654.  
  655.   return this.runtimeValue;
  656. }
  657.  
  658.  
  659. //--------------------------------------------------------------------
  660. // FUNCTION:
  661. //   CFColumnValueNode.setRuntimeValue
  662. //
  663. // DESCRIPTION:
  664. //   Given a runtime value from a SQL statement, this function sets
  665. //   the properties of this object to match this runtime code.
  666. //
  667. //   NOTE: This is an override of a base class function
  668. //
  669. // ARGUMENTS:
  670. //   runtimeValue - string - a SQL column value mapping
  671. //
  672. // RETURNS:
  673. //   nothing
  674. //--------------------------------------------------------------------
  675.  
  676. function CFColumnValueNode_setRuntimeValue(runtimeValue)
  677. {
  678.   this.runtimeValue = runtimeValue;
  679.  
  680.   // check if we have an altValue or defaultValue string
  681.   var paramObj = extPart.findInString("SQLVariable_altValue", this.runtimeValue);
  682.   if (paramObj != null)
  683.   {
  684.     // we have an alt value
  685.     this.varName = paramObj["Variable"];
  686.     this.wrapChar = "";
  687.     this.altValue = paramObj["AltValue"];
  688.     this.defaultValue = paramObj["DefaultValue"];
  689.   }
  690.   else
  691.   {
  692.     paramObj = extPart.findInString("SQLVariable_defaultValue", this.runtimeValue);
  693.     if (paramObj != null)
  694.     {
  695.       // we have a default value
  696.       this.varName = paramObj["Variable"];
  697.       this.wrapChar = this.decodeSQLVarRef(paramObj["RuntimeValue"]).wrapChar;
  698.       this.altValue = "";
  699.       this.defaultValue = paramObj["DefaultValue"];
  700.     }
  701.     else
  702.     {
  703.       // we have a normal value
  704.       var info = this.decodeSQLVarRef(this.runtimeValue);
  705.       this.varName = info.variable;
  706.       this.wrapChar = info.wrapChar;
  707.       this.altValue = "";
  708.       this.defaultValue = "NULL";
  709.     }
  710.   }
  711. }
  712.  
  713.  
  714. //--------------------------------------------------------------------
  715. // FUNCTION:
  716. //   getParameterTypeArray
  717. //
  718. // DESCRIPTION:
  719. //   Get list of available parameter types.
  720. //
  721. // ARGUMENTS:
  722. //   bRemoveEnteredVal - boolean (optional). 'true' if should remove 'Entered Value'
  723. //     as a possible parameter type. Defaults to 'false'.
  724. //
  725. // RETURNS:
  726. //   array of strings - localized list of parameter types.
  727. //--------------------------------------------------------------------
  728.  
  729. function getParameterTypeArray(bRemoveEnteredVal)
  730. {
  731.   // Make a copy of MM.LABEL_CF_Param_Types. We may need to alter it and we
  732.   //   don't want to affect the original array.
  733.   var paramTypes = new Array();
  734.   for (var i = 0; i < MM.LABEL_CF_Param_Types.length; ++i)
  735.   {
  736.     paramTypes.push(MM.LABEL_CF_Param_Types[i]);
  737.   }
  738.  
  739.   if (bRemoveEnteredVal)
  740.   {
  741.     paramTypes.splice(paramTypes.length - 1, 1);
  742.   }
  743.  
  744.   return paramTypes;
  745. }
  746.  
  747.  
  748. //--------------------------------------------------------------------
  749. // FUNCTION:
  750. //   getParameterCodeFromType
  751. //
  752. // DESCRIPTION:
  753. //   Gets the runtime code and default value for the parameter type.
  754. //
  755. // ARGUMENTS:
  756. //   paramType - string. one of elements returned from getParameterTypeArray.
  757. //   paramNameOrValue - string. Value for the parameter.
  758. //
  759. // RETURNS:
  760. //   object - with runtimeVal, defaultVal, and nameVal properties. null
  761. //     if no parameter is used.
  762. //--------------------------------------------------------------------
  763.  
  764. function getParameterCodeFromType(paramType, paramNameOrValue, paramDefault)
  765. {
  766.   var runtimeVal = dwscripts.sprintf(MM.MSG_UnknownParamType, paramType);
  767.   var nameVal = "";
  768.   var defaultVal = "1";
  769.  
  770.   switch(paramType)
  771.   {
  772.     case MM.LABEL_CF_Param_Types[0]:
  773.       runtimeVal = "#URL." + paramNameOrValue + "#";
  774.       nameVal = "URL." + paramNameOrValue;
  775.       break;
  776.     case MM.LABEL_CF_Param_Types[1]:
  777.       runtimeVal = "#FORM." + paramNameOrValue + "#";
  778.       nameVal = "FORM." + paramNameOrValue;
  779.       break;
  780.     case MM.LABEL_CF_Param_Types[2]:
  781.       runtimeVal = "#COOKIE." + paramNameOrValue + "#";
  782.       nameVal = "COOKIE." + paramNameOrValue;
  783.       break;
  784.     case MM.LABEL_CF_Param_Types[3]:
  785.       runtimeVal = "#SESSION." + paramNameOrValue + "#";
  786.       nameVal = "SESSION." + paramNameOrValue;
  787.       break;
  788.     case MM.LABEL_CF_Param_Types[4]:
  789.       runtimeVal = "#APPLICATION." + paramNameOrValue + "#";
  790.       nameVal = "APPLICATION." + paramNameOrValue;
  791.       break;
  792.   }
  793.  
  794.   var outObj = new Object();
  795.   if (paramType == MM.LABEL_CF_Param_Types[5])
  796.   {
  797.     outObj = null;
  798.   }
  799.   else
  800.   {
  801.     outObj.defaultVal = defaultVal;
  802.     outObj.runtimeVal = runtimeVal;
  803.     outObj.nameVal = nameVal;
  804.   }
  805.  
  806.   return outObj;
  807. }
  808.  
  809.  
  810. //--------------------------------------------------------------------
  811. // FUNCTION:
  812. //   getParameterTypeFromCode
  813. //
  814. // DESCRIPTION:
  815. //   Get parameter type and name from its runtime value.
  816. //
  817. // ARGUMENTS:
  818. //   runtimeValue - string - the runtime code
  819. //
  820. // RETURNS:
  821. //   object - contains paramType (one of elements returned from getParameterTypeArray)
  822. //     and paramName properties.
  823. //--------------------------------------------------------------------
  824.  
  825. function getParameterTypeFromCode(runtimeValue)
  826. {
  827.   var runtimeVal = runtimeValue;
  828.  
  829.   var outObj = new Object();
  830.  
  831.   var paramType = -1;
  832.   var paramName = runtimeValue;
  833.  
  834.   if (runtimeVal.search(/\s*url\.([^"]*)\s*/i) != -1)
  835.   {
  836.     paramType = MM.LABEL_CF_Param_Types[0];
  837.   }
  838.   else if (runtimeVal.search(/\s*form\.([^"]*)\s*/i) != -1)
  839.   {
  840.     paramType = MM.LABEL_CF_Param_Types[1];
  841.   }
  842.   else if (runtimeVal.search(/\s*cookie\.([^"]*)\s*/i) != -1)
  843.   {
  844.     paramType = MM.LABEL_CF_Param_Types[2];
  845.   }
  846.   else if (runtimeVal.search(/\s*session\.([^"]*)\s*/i) != -1)
  847.   {
  848.     paramType = MM.LABEL_CF_Param_Types[3];
  849.   }
  850.   else if (runtimeVal.search(/\s*application\.([^"]*)\s*/i) != -1)
  851.   {
  852.     paramType = MM.LABEL_CF_Param_Types[4];
  853.   }
  854.   else
  855.   {
  856.     paramType = MM.LABEL_CF_Param_Types[5];
  857.   }
  858.  
  859.   if (paramType == MM.LABEL_CF_Param_Types[5])
  860.   {
  861.     paramName = runtimeValue;
  862.   }
  863.   else
  864.   {
  865.     paramName = RegExp.$1;
  866.   }
  867.  
  868.   if (paramType != -1)
  869.   {
  870.     outObj.paramType = paramType;
  871.     outObj.paramName = paramName;
  872.     return outObj;
  873.   }
  874.   else
  875.   {
  876.     return false;
  877.   }
  878. }
  879.  
  880.  
  881. //--------------------------------------------------------------------
  882. // FUNCTION:
  883. //   isValidServerVarName
  884. //
  885. // DESCRIPTION:
  886. //   Returns true if the given variable name is legal
  887. //
  888. // ARGUMENTS:
  889. //   theVarName - string - variable to check
  890. //
  891. // RETURNS:
  892. //   boolean
  893. //--------------------------------------------------------------------
  894.  
  895. function isValidServerVarName(theVarName)
  896. {
  897.   var retVal = true;
  898.  
  899.   var parts = theVarName.split(".");
  900.  
  901.   for (var i=0; i < parts.length; i++)
  902.   {
  903.     if (!dwscripts.isValidVarName(parts[i]))
  904.     {
  905.       retVal = false;
  906.       break;
  907.     }
  908.   }
  909.  
  910.   return retVal;
  911. }
  912.  
  913.  
  914.